package com.spundhan.xtrac;

import android.app.Activity;
import android.content.SharedPreferences;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.Toast;

import com.spundhan.xtrac.db.DataBaseHelper;
import com.spundhan.xtrac.db.Database;

public class SplashScreenActivity extends Activity {

	private SQLiteDatabase db = null;
	SharedPreferences prefs = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		db = this.openOrCreateDatabase(Database.DATABASE_NAME, MODE_PRIVATE,
				null);

		prefs = PreferenceManager
				.getDefaultSharedPreferences(getApplicationContext());
		
		Database.DATABASE_PATH = this.getFilesDir().getParent() + "/databases/";
		
	}

	@Override
	protected void onResume() {
		super.onResume();

		if (prefs.getBoolean("firstrun", true)) {

			DataBaseHelper database = new DataBaseHelper(this);

			try {

				database.createDatabase();
//				database.openDataBase();

			} catch (SQLException sqle) {

				Toast.makeText(getApplicationContext(),
						"Unable to create database", Toast.LENGTH_SHORT).show();
			} catch (Exception e) {
				e.printStackTrace();
			}
			prefs.edit().putBoolean("firstrun", false).commit();
		}
	}
}
